﻿using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;

///<summary>
///SoldierAttckState 攻击状态类
///</summary>
class SoldierAttckState:ISoldierState
{
    /// <summary>
    /// 攻击间隔
    /// </summary>
    private float mAttackTime = 1;

    private float mAttackTimer = 1;
    public override void Reason(List<ICharacter> targets)
    {
        if (targets == null ||targets.Count == 0)
        {//没有敌人了
            mFsm.PerformTransition(SoldierTransition.NoEnemy);return;
        }
        float distance = Vector3.Distance(mCharacter.Position,targets[0].Position);
        if (distance>mCharacter.atkRange)
        {
            mFsm.PerformTransition(SoldierTransition.SeeEnemy);return;
        }
    }

    public override void Act(List<ICharacter> targets)
    {
        if (targets == null || targets.Count == 0) return;
        mAttackTimer += Time.deltaTime;
        if (mAttackTimer>=mAttackTime)
        {
            mCharacter.Attack(targets[0]);
            mAttackTimer = 0;
        }

    }

    public SoldierAttckState(SoldierFSMSystem fsm,ICharacter c) : base(fsm,c)
    {
        mStateID = SoldierStateID.Attack;
        mAttackTimer = mAttackTime;
    }
}

